<script>
function page(page)
{
	$('#firtclass').html('<img style=\'margin-top:100px;\' src=\'images/loading.gif\' align="absmiddle"/>'); 
	$.get(
			'firstclass_inquiry_ajax.php',
			{
				page:page,
				status:'<?=$_GET['status']?>'
			},
			function(data){
				$('#firstclass').html(data).hide().fadeIn('slow');
			},
			'html'
		);	
}
</script>
<? 
@session_start(); 
include("include/db_connect.php"); 
connect();
$sql="SET CHARACTER SET UTF8";   
query($sql); 
include "try_session_login.php";

$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end=20;

$limit_start = ($page-1)*$limit_end;

$send = "type=".$_GET['type'];

$sql = "select * from tb_firstclass where 1";

if(is_numeric($_GET['status'])){
	$sql.=" and active = '".$_GET['status']."'";
}
if($_POST['keyword']){
	$sql .= " and 
	name like '%".$_POST[keyword]."%'
	or email like '%".$_POST[keyword]."%'
	or tel like '%".$_POST[keyword]."%'
	or name like '%".$_POST[keyword]."%'
	";
}
$qr=select($sql. " LIMIT " . $limit_start. "," . $limit_end); 
$total=count($qr);
$rows = mysql_num_rows(mysql_query($sql));
$i=0;

?>

<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
  <tr>
    <td align="center">สมาชิกทั้งหมด <?=$rows?> คน</td>
  </tr>
</table>
<table width="100%" border="1" align="center" cellpadding="3" cellspacing="0" style="border-collapse:collapse;" id="tbl_content">
  <tr class="ui-widget-header">
    <td width="79" align="center" >ลำดับ</td>
    <td width="365" align="center"  >ชื่อ-นามสกุล</td>
    <td width="280" align="center"  >เบอร์โทรศัพท์</td>
    <td width="142" align="center"  >อีเมลล์</td>
    <td width="262" align="center"  >สถานะ</td>
    <td width="64" align="center" >ตัวเลือก</td>
  </tr>
  <?php
  
if($total > 0){ 
	while($i<count($qr)){ 
	$rs=$qr[$i];
	if($bg=='#fff'){$bg='#f2f2f2';}else{$bg='#fff';}
	if($rs[active]==0){$rs[active]="offline"; $text='<span style="color:black;">ยังไม่ติดต่อ</span>'; }else{$rs['active']="online"; $text='<span style="color:green;">ติดต่อแล้ว</span>';} 
?>
  <tr  bgcolor="<?=$bg?>"  onmouseout="this.className=''" onmouseover="this.className='ui-state-error'" id="list<?=$rs['id']?>">
    <td align="center" ><?=$limit_start+$i+1;?></td>
    <td align="center"><? echo $rs['name'] ?></td>
    <td align="center"><?=$rs['tel']?></td>
    <td align="center"><?=$rs['email']?></td>
    <td align="center" valign="middle">
      <div id="active<?=$rs['id']?>"><a onclick="active('<?=$rs['id']?>','<?=$rs[active] ?>')" href="javascript:void(0);"><?php echo $text; ?></a></div> 
    </td>
    <td align="center" valign="middle">
     	<ul id="icons" class="ui-widget ui-helper-clearfix">
			<li class="ui-state-default ui-corner-all" title="ดูประวัติ" onclick="ViewInquiry('<?=$rs['id']?>');"><span class="ui-icon ui-icon-contact"></span></li>
            <li class="ui-state-default ui-corner-all" title="ลบรายชื่อ" onclick="DeleteMember('<?=$rs['id']?>');"><span class="ui-icon ui-icon-trash"></span></li>
         </ul>
     </td>
  </tr>
  <?php 
  $i++;
	}//end while//
}//end if($total > 0)//
  ?>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
	<?php if(($rows/$limit_end) > 1){ 
		if($_GET[type]<>''){
			echo "\n<div>" . page_navi5($page, $limit_end, 4, $rows, $send,"mynavic","mynavi") . " </div>";
		}else{
			echo "\n<div>" . page_navi2($page, $limit_end, 4, $rows, $send,"mynavic","mynavi") . " </div>";
		}
	}
	?></td>
  </tr>
</table>